package leetCode;

import java.util.*;

public class groupAnagram {
    public static void main(String[] args) {
        String[] s = {"eat", "tea", "tan", "ate", "nat", "bat"};
        List<List<String>> lists = groupAnagrams(s);
        System.out.println(lists);
    }
    public static List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> map = new HashMap<>();
        for(int i =0;i<strs.length;i++){
            char[] chars = strs[i].toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            List<String> tem = map.getOrDefault(key, new ArrayList<>());
            tem.add(strs[i]);
            map.put(key,tem);
        }
        return new ArrayList<>(map.values());
    }
}
